from flask import Blueprint, jsonify, request
import service.analysis as service_analysis

bp = Blueprint('analysis', __name__)


@bp.post('/health')
def health():
    file_path = 'file_path'
    columns = [6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]
    res = service_analysis.kmo(file_path, columns)
    return jsonify(res)


@bp.post('/kmo')
def kmo():
    """
    :describe: 进行kmo和bartlett检验
    :param: file_path -> 文件地址,              :type: string
    :param: columns -> 需要参与计算的列index     :type: array
    :return: json统一返回格式
    """
    data = request.get_json()
    file_path = data.get('file_path')
    columns = data.get('columns')
    res = service_analysis.kmo(file_path, columns)
    return jsonify(res)


@bp.post('/alpha')
def alpha():
    data = request.get_json()
    file_path = data.get('file_path')
    columns = data.get('columns')
    res = service_analysis.alpha(file_path, columns)
    return jsonify(res)


@bp.post('/describe')
def describe():
    data = request.get_json()
    file_path = data.get('file_path')
    columns = data.get('columns')
    res = service_analysis.describe(file_path, columns)
    return jsonify(res)
